package com.iuhao.web.controller;

import com.alibaba.fastjson.JSONObject;


import com.iuhao.web.core.response.O2OJSON;
import com.iuhao.web.core.utils.*;
import com.iuhao.web.core.utils.DateUtil;
import com.iuhao.web.core.utils.EncryptionUtil;
import com.iuhao.web.core.utils.HttpRequestUtil;
import com.iuhao.web.test.TestService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yanhao on 2017/11/7.
 */
@Api(tags = "TestController", description = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController extends BaseController{


    /**
     *
     Post 请求参数：
     data=DATA
     先将GET 字段与POST 字段合并
     open_id=OPEN_ID&lang=zh-cn&timestamp=TIMESTAMP&randStr=RANDSTR&d
     ata=DATA
     按a-Z 排序
     data=DATA&open_id=OPEN_ID&randStr=RANDSTR&timestamp=TIMESTAMP
     sha1 加密后转小写
     697582242643fcf49dc36fa17c1f44d07032ac48
     */



    @PostMapping(value = "/testOrder")
    @ApiOperation(value = "testOrder")
    public O2OJSON testCON() throws Exception {
        O2OJSON json = new O2OJSON();
        Date currentDate = DateUtil.getCurrentDate();

        String date = DateUtil.format(currentDate, DateUtil.PATTERN_CLASSICAL_SIMPLE);//2017-07-28

        String open_id="txaOzhP37377a3e326136f11f36ac23b";
        String open_key="dvpDi1yBfE3JQPM09ABcPvN9vc4Nr2mE";

        String lang ="zh-cn";
        String timestamp= System.currentTimeMillis()/1000+"";
        String randStr= "11544551154455551125444555441012";

        String privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDbQ2aRTPwhSFFx\n" +
                "dx8evrHRbeUWSZ9GD5pvLAGyztzqB6OchEHnU8KfPSa8zkgWjU8TVOrfu4sQZJlw\n" +
                "vFNEUQVwtWTemzMSjpUQG+0p8/ObauloCXMeO15mGD/rPjxWugeb2+jaVk1fZubz\n" +
                "mP8NNA3643+szo9UVw5dCcuHYIpHS3zm4mcs6fcHQ/7lxcSeOtObySYcByqA3IMo\n" +
                "30Pt9U8EU6R8htTzK1WzhjqTwcyb5mMKlK/KzzLR/dZeqFdvsEtcGAoxK1FzNIZ7\n" +
                "N1ZdsdMkcZ9V5go3XThdUVkSKN230UOI9A1T0EIl8p7SC2hLHhi4HdmH4pM2r0tf\n" +
                "aSO7sP9PAgMBAAECggEAfEwZOQWLaNK2WLxOx/8Sjsbdt2TFBdKSmbM4w0TBt2nd\n" +
                "Nj1Dnv+8tMjVzPKjqyUwTqU1AOAwVXqyAVbBXVkQ3HP4WrlgmoR5vEgYik/hKZnR\n" +
                "90hkGh9NxFK66YC+c+vBpHll52BFPG/5PN7et31q729IUY5HcmhnnBaRao0v1nnH\n" +
                "rWeYIKiIGJUWwwYd95vzFVlnfjZE68cpT3n7MR06KDIawnGckhd1htBfnnZJJR4B\n" +
                "JTDBWDHtDF1tSd8H4WPjeEDS7s5q/GOiklyL3bqR5zUM3kFlZhDyQtm1dR6VN0CY\n" +
                "8jNUo4JidwLMN0uACk6n6XHM2jtDb69CCrNyDSDFAQKBgQD6YPB3qbU6VNSqqAU2\n" +
                "fiKVWCvf9SuGfOpkxky9aWuFc+HbmhlHsi2uY24zlKP8HtQupBdos+Xc3faAbiF7\n" +
                "F52ot4JFncnL+oLNgSST3rQPfs6PVlkEDAtLaNsZi5PDQPi+gq/62dOQ1y4Dli2+\n" +
                "ZO0cY6r2EtUiBepVLAFV3ElCkwKBgQDgL5/fI4EwrA9OV5J2xKEZir/qCm3PcJGd\n" +
                "dRJXeZDEA65m11FVqZcRmwXm7ACn8sTEJOCtj2RWoGMbdPZPqZOYFeRovXyvgy1u\n" +
                "E2/SockteX03/wL3WCXg6Vq9G7j5PSUkUO5ALtvMCJzk6+GxPvOPrZLthG56YES6\n" +
                "tSG1LDrZ1QKBgE52tqUpf+vJzeO1R/ztxnS67vT+Zid9Wg8+vanWMaXezPb+8dEw\n" +
                "G3S9IDn16PYHy0LalaNwTSbMQIW6/a8PlY7cA21Bp43O8dLpF8dnUVJR0PXGf5rv\n" +
                "E1MMhy0YOrRD1jAN0IxyWwTXCkqBc9Bo3I27BkabXEOPSwJqCfkYUbUVAoGBAN8y\n" +
                "ixi9YIH0y8hTp55XZYzodumsOGeuy0rYo8ozXc3JXHlHJdMDZURB8z5U+NI9AWnG\n" +
                "zWn+uQcF56YObKwjSK7CHQWqodib4T8WWt559LExo1l8qpdXS18A9TYRw7dhCPl/\n" +
                "GbUM8gfRC2Ne9PRimFsTlJSkpNlxvvukGksmHfGBAoGAF2Ca5pJOmli6dC7yTAGM\n" +
                "TvJlODvwzU97RzpuMfaPunlsLm3mFunoWqAiznWchVz7ncIpFEAnvJM75JSY8TNf\n" +
                "kCs0euW/xi7GVgANba51RUpGl6ztyIdQQGWw6agcibNGRlPF+a02SHTNG7G35ZAL\n" +
                "T1K+QSBdq/jheKHrc6Flj6M=";

        JSONObject object = new JSONObject();
        object.put("day",date);
        object.put("tar_type","gzip");

        String data= EncryptionUtil.encrypt(object.toJSONString());

        Map<String,Object> map = new HashMap<>();
        /*String open_id="txaOzhP37377a3e326136f11f36ac23b";
        String randStr="12345678912345678946512345669879";
        Long l = System.currentTimeMillis() /1000;
        String timestamp=l.toString();*/

        map.put("data",data );
        map.put("open_id",open_id );
        map.put("randStr",randStr );
        map.put("timestamp",timestamp );
        String signContent = PaySignature.getSignContent(map);

        byte[] bytes = PaySignature.rsaSign2(signContent, privateKey);

        String sign = PaySignature.bin2hex(bytes);

        System.out.println(sign);
        String url="https://api.tlinx.com/org1/bill/downloadbill?"+"open_id="+open_id+"&lang="+lang+"&timestamp="+timestamp+"&randStr="+randStr+"&data="+data+"&sign="+sign;

        log.info(url);
        try {
            String doGet = HttpRequestUtil.doGet(url, O2OJSON.class);

            log.info(doGet);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return json;
    }
/*

    public static void main(String[] args) {
        String s = SMSCodeUtil.generateSMSCode();
        System.out.println(s);
    }
*/


/**
 *






 String key = "dvpDi1yBfE3JQPM09ABcPvN9vc4Nr2mE";
 JSONObject datas = new JSONObject();
 datas.put("day", "2017-11-14");
 datas.put("tar_type", "gzip");
 //String keys = PaySignature.getRandomStringByLength(32);
 data = PaySignature.AESEncrypt(datas.toString(), key);
 System.out.println(data);
 Map<String,Object> map = new HashMap<>();
 String open_id="txaOzhP37377a3e326136f11f36ac23b";
 String randStr="12345678912345678946512345669879";
 Long l = System.currentTimeMillis() /1000;
 String timestamp=l.toString();
 map.put("data",data );
 map.put("open_id",open_id );
 map.put("randStr",randStr );
 map.put("timestamp",timestamp );
 String signContent = PaySignature.getSignContent(map);

 String privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDbQ2aRTPwhSFFx\n" +
 "dx8evrHRbeUWSZ9GD5pvLAGyztzqB6OchEHnU8KfPSa8zkgWjU8TVOrfu4sQZJlw\n" +
 "vFNEUQVwtWTemzMSjpUQG+0p8/ObauloCXMeO15mGD/rPjxWugeb2+jaVk1fZubz\n" +
 "mP8NNA3643+szo9UVw5dCcuHYIpHS3zm4mcs6fcHQ/7lxcSeOtObySYcByqA3IMo\n" +
 "30Pt9U8EU6R8htTzK1WzhjqTwcyb5mMKlK/KzzLR/dZeqFdvsEtcGAoxK1FzNIZ7\n" +
 "N1ZdsdMkcZ9V5go3XThdUVkSKN230UOI9A1T0EIl8p7SC2hLHhi4HdmH4pM2r0tf\n" +
 "aSO7sP9PAgMBAAECggEAfEwZOQWLaNK2WLxOx/8Sjsbdt2TFBdKSmbM4w0TBt2nd\n" +
 "Nj1Dnv+8tMjVzPKjqyUwTqU1AOAwVXqyAVbBXVkQ3HP4WrlgmoR5vEgYik/hKZnR\n" +
 "90hkGh9NxFK66YC+c+vBpHll52BFPG/5PN7et31q729IUY5HcmhnnBaRao0v1nnH\n" +
 "rWeYIKiIGJUWw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GWw6agcibNGRlPF+a02SHTNG7G35ZAL\n" +
 "T1K+QSBdqeKHrc6Flj6M=\n";
 byte[] bytes = PaySignature.rsaSign2(signContent, privateKey);

 String sign = PaySignature.bin2hex(bytes)


















 */


}
